package com.cbgolf.oa.activity.result;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.cbgolf.oa.R;
import com.cbgolf.oa.base.BaseActivity;
import com.cbgolf.oa.entity.ResultBean;
import com.cbgolf.oa.entity.NetResponse;
import com.cbgolf.oa.inteface.IAsynTask;
import com.cbgolf.oa.inteface.INetCallBack;
import com.cbgolf.oa.net.NetCallBack;
import com.cbgolf.oa.net.Web;
import com.cbgolf.oa.net.WebAPI;
import com.cbgolf.oa.user.UserData;
import com.cbgolf.oa.util.AnimaUtil;
import com.cbgolf.oa.util.Util;
import com.cbgolf.oa.widget.autolayout.utils.AutoUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by lq on 2017/7/12.
 */

public class ScoreWriteActivity extends BaseActivity {

    //top
    @ViewInject(R.id.topBack_ll)
    private View topBack;
    @ViewInject(R.id.title_tv)
    private TextView topTitle;
    //body
    //mem
    @ViewInject(R.id.a_match_result_group_mem1_tv)
    private TextView mem1NameTv;
    @ViewInject(R.id.a_match_result_group_mem2_tv)
    private TextView mem2NameTv;
    @ViewInject(R.id.a_match_result_group_mem3_tv)
    private TextView mem3NameTv;
    @ViewInject(R.id.a_match_result_group_mem4_tv)
    private TextView mem4NameTv;
    //a
    //a1
    @ViewInject(R.id.a_match_result_group_a1_par_tv)
    private TextView a1_parTv;
    @ViewInject(R.id.a_match_result_group_a1_mem1_tv)
    private TextView a1_mem1Tv;
    @ViewInject(R.id.a_match_result_group_a1_mem2_tv)
    private TextView a1_mem2Tv;
    @ViewInject(R.id.a_match_result_group_a1_mem3_tv)
    private TextView a1_mem3Tv;
    @ViewInject(R.id.a_match_result_group_a1_mem4_tv)
    private TextView a1_mem4Tv;
    //a2
    @ViewInject(R.id.a_match_result_group_a2_par_tv)
    private TextView a2_parTv;
    @ViewInject(R.id.a_match_result_group_a2_mem1_tv)
    private TextView a2_mem1Tv;
    @ViewInject(R.id.a_match_result_group_a2_mem2_tv)
    private TextView a2_mem2Tv;
    @ViewInject(R.id.a_match_result_group_a2_mem3_tv)
    private TextView a2_mem3Tv;
    @ViewInject(R.id.a_match_result_group_a2_mem4_tv)
    private TextView a2_mem4Tv;
    //a3
    @ViewInject(R.id.a_match_result_group_a3_par_tv)
    private TextView a3_parTv;
    @ViewInject(R.id.a_match_result_group_a3_mem1_tv)
    private TextView a3_mem1Tv;
    @ViewInject(R.id.a_match_result_group_a3_mem2_tv)
    private TextView a3_mem2Tv;
    @ViewInject(R.id.a_match_result_group_a3_mem3_tv)
    private TextView a3_mem3Tv;
    @ViewInject(R.id.a_match_result_group_a3_mem4_tv)
    private TextView a3_mem4Tv;
    //a4
    @ViewInject(R.id.a_match_result_group_a4_par_tv)
    private TextView a4_parTv;
    @ViewInject(R.id.a_match_result_group_a4_mem1_tv)
    private TextView a4_mem1Tv;
    @ViewInject(R.id.a_match_result_group_a4_mem2_tv)
    private TextView a4_mem2Tv;
    @ViewInject(R.id.a_match_result_group_a4_mem3_tv)
    private TextView a4_mem3Tv;
    @ViewInject(R.id.a_match_result_group_a4_mem4_tv)
    private TextView a4_mem4Tv;
    //a5
    @ViewInject(R.id.a_match_result_group_a5_par_tv)
    private TextView a5_parTv;
    @ViewInject(R.id.a_match_result_group_a5_mem1_tv)
    private TextView a5_mem1Tv;
    @ViewInject(R.id.a_match_result_group_a5_mem2_tv)
    private TextView a5_mem2Tv;
    @ViewInject(R.id.a_match_result_group_a5_mem3_tv)
    private TextView a5_mem3Tv;
    @ViewInject(R.id.a_match_result_group_a5_mem4_tv)
    private TextView a5_mem4Tv;
    //a6
    @ViewInject(R.id.a_match_result_group_a6_par_tv)
    private TextView a6_parTv;
    @ViewInject(R.id.a_match_result_group_a6_mem1_tv)
    private TextView a6_mem1Tv;
    @ViewInject(R.id.a_match_result_group_a6_mem2_tv)
    private TextView a6_mem2Tv;
    @ViewInject(R.id.a_match_result_group_a6_mem3_tv)
    private TextView a6_mem3Tv;
    @ViewInject(R.id.a_match_result_group_a6_mem4_tv)
    private TextView a6_mem4Tv;
    //a7
    @ViewInject(R.id.a_match_result_group_a7_par_tv)
    private TextView a7_parTv;
    @ViewInject(R.id.a_match_result_group_a7_mem1_tv)
    private TextView a7_mem1Tv;
    @ViewInject(R.id.a_match_result_group_a7_mem2_tv)
    private TextView a7_mem2Tv;
    @ViewInject(R.id.a_match_result_group_a7_mem3_tv)
    private TextView a7_mem3Tv;
    @ViewInject(R.id.a_match_result_group_a7_mem4_tv)
    private TextView a7_mem4Tv;
    //a8
    @ViewInject(R.id.a_match_result_group_a8_par_tv)
    private TextView a8_parTv;
    @ViewInject(R.id.a_match_result_group_a8_mem1_tv)
    private TextView a8_mem1Tv;
    @ViewInject(R.id.a_match_result_group_a8_mem2_tv)
    private TextView a8_mem2Tv;
    @ViewInject(R.id.a_match_result_group_a8_mem3_tv)
    private TextView a8_mem3Tv;
    @ViewInject(R.id.a_match_result_group_a8_mem4_tv)
    private TextView a8_mem4Tv;
    //a9
    @ViewInject(R.id.a_match_result_group_a9_par_tv)
    private TextView a9_parTv;
    @ViewInject(R.id.a_match_result_group_a9_mem1_tv)
    private TextView a9_mem1Tv;
    @ViewInject(R.id.a_match_result_group_a9_mem2_tv)
    private TextView a9_mem2Tv;
    @ViewInject(R.id.a_match_result_group_a9_mem3_tv)
    private TextView a9_mem3Tv;
    @ViewInject(R.id.a_match_result_group_a9_mem4_tv)
    private TextView a9_mem4Tv;
    //a_out
    @ViewInject(R.id.a_match_result_group_a_out_par_tv)
    private TextView out_parTv;
    @ViewInject(R.id.a_match_result_group_a_out_mem1_tv)
    private TextView out_mem1Tv;
    @ViewInject(R.id.a_match_result_group_a_out_mem2_tv)
    private TextView out_mem2Tv;
    @ViewInject(R.id.a_match_result_group_a_out_mem3_tv)
    private TextView out_mem3Tv;
    @ViewInject(R.id.a_match_result_group_a_out_mem4_tv)
    private TextView out_mem4Tv;
    //b
    //b1
    @ViewInject(R.id.a_match_result_group_b1_par_tv)
    private TextView b1_parTv;
    @ViewInject(R.id.a_match_result_group_b1_mem1_tv)
    private TextView b1_mem1Tv;
    @ViewInject(R.id.a_match_result_group_b1_mem2_tv)
    private TextView b1_mem2Tv;
    @ViewInject(R.id.a_match_result_group_b1_mem3_tv)
    private TextView b1_mem3Tv;
    @ViewInject(R.id.a_match_result_group_b1_mem4_tv)
    private TextView b1_mem4Tv;
    //b2
    @ViewInject(R.id.a_match_result_group_b2_par_tv)
    private TextView b2_parTv;
    @ViewInject(R.id.a_match_result_group_b2_mem1_tv)
    private TextView b2_mem1Tv;
    @ViewInject(R.id.a_match_result_group_b2_mem2_tv)
    private TextView b2_mem2Tv;
    @ViewInject(R.id.a_match_result_group_b2_mem3_tv)
    private TextView b2_mem3Tv;
    @ViewInject(R.id.a_match_result_group_b2_mem4_tv)
    private TextView b2_mem4Tv;
    //b3
    @ViewInject(R.id.a_match_result_group_b3_par_tv)
    private TextView b3_parTv;
    @ViewInject(R.id.a_match_result_group_b3_mem1_tv)
    private TextView b3_mem1Tv;
    @ViewInject(R.id.a_match_result_group_b3_mem2_tv)
    private TextView b3_mem2Tv;
    @ViewInject(R.id.a_match_result_group_b3_mem3_tv)
    private TextView b3_mem3Tv;
    @ViewInject(R.id.a_match_result_group_b3_mem4_tv)
    private TextView b3_mem4Tv;
    //b4
    @ViewInject(R.id.a_match_result_group_b4_par_tv)
    private TextView b4_parTv;
    @ViewInject(R.id.a_match_result_group_b4_mem1_tv)
    private TextView b4_mem1Tv;
    @ViewInject(R.id.a_match_result_group_b4_mem2_tv)
    private TextView b4_mem2Tv;
    @ViewInject(R.id.a_match_result_group_b4_mem3_tv)
    private TextView b4_mem3Tv;
    @ViewInject(R.id.a_match_result_group_b4_mem4_tv)
    private TextView b4_mem4Tv;
    //b5
    @ViewInject(R.id.a_match_result_group_b5_par_tv)
    private TextView b5_parTv;
    @ViewInject(R.id.a_match_result_group_b5_mem1_tv)
    private TextView b5_mem1Tv;
    @ViewInject(R.id.a_match_result_group_b5_mem2_tv)
    private TextView b5_mem2Tv;
    @ViewInject(R.id.a_match_result_group_b5_mem3_tv)
    private TextView b5_mem3Tv;
    @ViewInject(R.id.a_match_result_group_b5_mem4_tv)
    private TextView b5_mem4Tv;
    //b6
    @ViewInject(R.id.a_match_result_group_b6_par_tv)
    private TextView b6_parTv;
    @ViewInject(R.id.a_match_result_group_b6_mem1_tv)
    private TextView b6_mem1Tv;
    @ViewInject(R.id.a_match_result_group_b6_mem2_tv)
    private TextView b6_mem2Tv;
    @ViewInject(R.id.a_match_result_group_b6_mem3_tv)
    private TextView b6_mem3Tv;
    @ViewInject(R.id.a_match_result_group_b6_mem4_tv)
    private TextView b6_mem4Tv;
    //b7
    @ViewInject(R.id.a_match_result_group_b7_par_tv)
    private TextView b7_parTv;
    @ViewInject(R.id.a_match_result_group_b7_mem1_tv)
    private TextView b7_mem1Tv;
    @ViewInject(R.id.a_match_result_group_b7_mem2_tv)
    private TextView b7_mem2Tv;
    @ViewInject(R.id.a_match_result_group_b7_mem3_tv)
    private TextView b7_mem3Tv;
    @ViewInject(R.id.a_match_result_group_b7_mem4_tv)
    private TextView b7_mem4Tv;
    //b8
    @ViewInject(R.id.a_match_result_group_b8_par_tv)
    private TextView b8_parTv;
    @ViewInject(R.id.a_match_result_group_b8_mem1_tv)
    private TextView b8_mem1Tv;
    @ViewInject(R.id.a_match_result_group_b8_mem2_tv)
    private TextView b8_mem2Tv;
    @ViewInject(R.id.a_match_result_group_b8_mem3_tv)
    private TextView b8_mem3Tv;
    @ViewInject(R.id.a_match_result_group_b8_mem4_tv)
    private TextView b8_mem4Tv;
    //b9
    @ViewInject(R.id.a_match_result_group_b9_par_tv)
    private TextView b9_parTv;
    @ViewInject(R.id.a_match_result_group_b9_mem1_tv)
    private TextView b9_mem1Tv;
    @ViewInject(R.id.a_match_result_group_b9_mem2_tv)
    private TextView b9_mem2Tv;
    @ViewInject(R.id.a_match_result_group_b9_mem3_tv)
    private TextView b9_mem3Tv;
    @ViewInject(R.id.a_match_result_group_b9_mem4_tv)
    private TextView b9_mem4Tv;
    //in
    @ViewInject(R.id.a_match_result_group_IN_mem1_tv)
    private TextView in_mem1Tv;
    @ViewInject(R.id.a_match_result_group_IN_mem2_tv)
    private TextView in_mem2Tv;
    @ViewInject(R.id.a_match_result_group_IN_mem3_tv)
    private TextView in_mem3Tv;
    @ViewInject(R.id.a_match_result_group_IN_mem4_tv)
    private TextView in_mem4Tv;
    @ViewInject(R.id.a_match_result_group_IN_par_tv)
    private TextView in_ParTv;
    //all
    @ViewInject(R.id.a_match_result_group_zonggan_mem1_tv)
    private TextView all_mem1Tv;
    @ViewInject(R.id.a_match_result_group_zonggan_mem2_tv)
    private TextView all_mem2Tv;
    @ViewInject(R.id.a_match_result_group_zonggan_mem3_tv)
    private TextView all_mem3Tv;
    @ViewInject(R.id.a_match_result_group_zonggan_mem4_tv)
    private TextView all_mem4Tv;
    @ViewInject(R.id.a_match_result_group_zonggan_par_tv)
    private TextView all_ParTv;

    //submit
    @ViewInject(R.id.a_match_result_group_before_tv)
    private TextView modifyBeforeTv;
    @ViewInject(R.id.a_match_result_group_this_tv)
    private TextView writeThisTv;


    //a_par
    private int a1Par = -1;
    private int a2Par = -1;
    private int a3Par = -1;
    private int a4Par = -1;
    private int a5Par = -1;
    private int a6Par = -1;
    private int a7Par = -1;
    private int a8Par = -1;
    private int a9Par = -1;
    //b_par
    private int b1Par = -1;
    private int b2Par = -1;
    private int b3Par = -1;
    private int b4Par = -1;
    private int b5Par = -1;
    private int b6Par = -1;
    private int b7Par = -1;
    private int b8Par = -1;
    private int b9Par = -1;
    //out in all -par
    private int outPar = -1;
    private int inPar = -1;
    private int allPar = -1;
    //a-mem
    //mem1
    private int a1Mem1 = -1;
    private int a2Mem1 = -1;
    private int a3Mem1 = -1;
    private int a4Mem1 = -1;
    private int a5Mem1 = -1;
    private int a6Mem1 = -1;
    private int a7Mem1 = -1;
    private int a8Mem1 = -1;
    private int a9Mem1 = -1;
    //mem2
    private int a1Mem2 = -1;
    private int a2Mem2 = -1;
    private int a3Mem2 = -1;
    private int a4Mem2 = -1;
    private int a5Mem2 = -1;
    private int a6Mem2 = -1;
    private int a7Mem2 = -1;
    private int a8Mem2 = -1;
    private int a9Mem2 = -1;
    //mem3
    private int a1Mem3 = -1;
    private int a2Mem3 = -1;
    private int a3Mem3 = -1;
    private int a4Mem3 = -1;
    private int a5Mem3 = -1;
    private int a6Mem3 = -1;
    private int a7Mem3 = -1;
    private int a8Mem3 = -1;
    private int a9Mem3 = -1;
    //mem4
    private int a1Mem4 = -1;
    private int a2Mem4 = -1;
    private int a3Mem4 = -1;
    private int a4Mem4 = -1;
    private int a5Mem4 = -1;
    private int a6Mem4 = -1;
    private int a7Mem4 = -1;
    private int a8Mem4 = -1;
    private int a9Mem4 = -1;
    //out mem
    private int outMem1 = -1;
    private int outMem2 = -1;
    private int outMem3 = -1;
    private int outMem4 = -1;
    //b-mem
    //mem1
    private int b1Mem1 = -1;
    private int b2Mem1 = -1;
    private int b3Mem1 = -1;
    private int b4Mem1 = -1;
    private int b5Mem1 = -1;
    private int b6Mem1 = -1;
    private int b7Mem1 = -1;
    private int b8Mem1 = -1;
    private int b9Mem1 = -1;
    //mem2
    private int b1Mem2 = -1;
    private int b2Mem2 = -1;
    private int b3Mem2 = -1;
    private int b4Mem2 = -1;
    private int b5Mem2 = -1;
    private int b6Mem2 = -1;
    private int b7Mem2 = -1;
    private int b8Mem2 = -1;
    private int b9Mem2 = -1;
    //mem3
    private int b1Mem3 = -1;
    private int b2Mem3 = -1;
    private int b3Mem3 = -1;
    private int b4Mem3 = -1;
    private int b5Mem3 = -1;
    private int b6Mem3 = -1;
    private int b7Mem3 = -1;
    private int b8Mem3 = -1;
    private int b9Mem3 = -1;
    //mem4
    private int b1Mem4 = -1;
    private int b2Mem4 = -1;
    private int b3Mem4 = -1;
    private int b4Mem4 = -1;
    private int b5Mem4 = -1;
    private int b6Mem4 = -1;
    private int b7Mem4 = -1;
    private int b8Mem4 = -1;
    private int b9Mem4 = -1;
    //in all mem
    private int inMem1 = -1;
    private int inMem2 = -1;
    private int inMem3 = -1;
    private int inMem4 = -1;
    private int allMem1 = -1;
    private int allMem2 = -1;
    private int allMem3 = -1;
    private int allMem4 = -1;


    private final int BEFORE = 1;
    private final int CURRENT = BEFORE + 1;

    private String groupName;
    private String userName;
    private String mem1Name;
    private String mem2Name;
    private String mem3Name;
    private String mem4Name;
    private String mem1Phone;
    private String mem2Phone;
    private String mem3Phone;
    private String mem4Phone;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a_score_write);
    }


    @Override
    protected void findViews() {
        x.view().inject(this);
    }

    private ArrayList<String> listPhones;

    @Override
    protected void setViews() {
        topTitle.setText("记分卡");
        Intent intent = getIntent();
        if (null != intent) {
            if (intent.hasExtra("groupId")) {
                groupId = intent.getStringExtra("groupId");
            }
            if (intent.hasExtra("phones")) {
                listPhones = intent.getStringArrayListExtra("phones");
            }
        }
        for (int i = 1; i <= 18; i++) {
            stateMap.put(i, false);
        }
    }

    @Override
    protected void setListener() {
        topBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        if (null != modifyBeforeTv) {
            modifyBeforeTv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    checkModifyAble(BEFORE);
                }
            });
        }
        if (null != writeThisTv) {
            writeThisTv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    checkModifyAble(CURRENT);
                }
            });
        }

    }

    @Override
    protected void loadData() {
        super.loadData();
        getGroupInfo();

    }


    private void getGroupInfo() {
        if (!Util.isNetWorkConnected()) {
            Util.show("没有网络");
            return;
        }
        String url = WebAPI.groupinfo_post;
        Map<String, Object> map = new HashMap<>();
        JSONObject json = new JSONObject();
        try {
            json.put("groupId", groupId);
            JSONArray array = new JSONArray();
            if (null != listPhones && listPhones.size() > 0) {
                for (int i = 0; i < listPhones.size(); i++) {
                    array.put(listPhones.get(i));
                }
            }
            json.put("phones", array);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        map.put("data", json.toString());
        map.put("token", null == UserData.getUser() ? "" : UserData.getUser().getToken());
        AnimaUtil.showLoading(context);
        Web.postJsonOk(url, map, new NetCallBack(new INetCallBack() {
            @Override
            public void onResponse(NetResponse response) {
                AnimaUtil.stopLoading();
                if (200 != response.statusCode || Util.isNull(response.result)) {
                    Util.showNetError();
                    return;
                }
                List<ResultBean> list = null;
                try {
                    list = JSON.parseArray(response.result, ResultBean.class);
                } catch (Exception e) {
                    Util.showNetError();
                    return;
                }
                if (null != list && list.size() > 0) {
                    filteGroupResultInThread(list);
                }
            }

        }));
    }


    private Map<Integer, List<ResultBean.MemInfo>> dataMap = new HashMap<>(21);


    private void filteGroupResultInThread(final List<ResultBean> list) {
        Util.asynTask(new IAsynTask() {
            @Override
            public void updateUI(Serializable ser) {
                setDatas();
            }

            @Override
            public Serializable Run() {
                String hole;
                List<ResultBean.MemInfo> listMemInfo = new ArrayList<ResultBean.MemInfo>();
                String result;
                String name;
                String phone;
                String phoneOfMe = "";
                String on;
                String push;
                String par;
                if (null != UserData.getUser()) {
                    phoneOfMe = UserData.getUser().getPhone();
                }
                boolean isOk = true;
                for (int i = 0; i < list.size(); i++) {
                    hole = list.get(i).hole;
                    listMemInfo = list.get(i).list;
                    if (Util.isNull(hole)) {
                        continue;
                    }
                    if (null != listMemInfo && listMemInfo.size() > 0) {
                        isOk = true;
                        for (int j = 0; j < listMemInfo.size(); j++) {
                            result = listMemInfo.get(j).totalScore;
                            name = listMemInfo.get(j).name;
                            phone = listMemInfo.get(j).phone;
                            on = listMemInfo.get(j).onScore;
                            push = listMemInfo.get(j).pushScore;
                            par = listMemInfo.get(j).par;
                            if (Util.isNull(groupName)) {
                                groupName = listMemInfo.get(j).competitionName;
                            }
                            if (Util.isNull(groupId)) {
                                groupId = listMemInfo.get(j).competitionGroupId;
                            }
                            if (Util.isNull(userName)) {
                                if (!Util.isNull(phone) && !Util.isNull(phoneOfMe) && phoneOfMe.equals(phone)) {
                                    userName = name;
                                }
                            }
                            if (i == 0) {
                                if (j == 0) {
                                    mem1Name = name;
                                    mem1Phone = phone;
                                } else if (j == 1) {
                                    mem2Name = name;
                                    mem2Phone = phone;
                                } else if (j == 2) {
                                    mem3Name = name;
                                    mem3Phone = phone;
                                } else if (j == 3) {
                                    mem4Name = name;
                                    mem4Phone = phone;
                                }
                            }
//                            if (!Util.isNull(name) || !Util.isNull(phone)) {
//                                if (!Util.isNull(result)) {
//                                    setMemResult(hole, result, j);
//                                }
//
//                            }
                            if (!Util.isNull(result) && (!Util.isNull(name) || !Util.isNull(phone))) {
                                setMemResult(hole, result, j);
                            }
                            if (!Util.isNull(par))
                                setPars(hole, par);
                            if (!Util.isNull(name) || !Util.isNull(phone)) {
                                if (Util.isNull(result) || Util.isNull(on) || Util.isNull(push)) {
                                    isOk = false;
                                }
                            }

                        }
                    }
                    setDataMap(hole, listMemInfo, isOk);
                    getSum();
                }
                return "success";
            }
        });
    }

    private void setParData() {
        int[] Pars = {
                a1Par, a2Par, a3Par, a4Par, a5Par, a6Par, a7Par, a8Par, a9Par,
                b1Par, b2Par, b3Par, b4Par, b5Par, b6Par, b7Par, b8Par, b9Par
        };
        TextView[] parTvs = {
                a1_parTv, a2_parTv, a3_parTv, a4_parTv, a5_parTv, a6_parTv, a7_parTv, a8_parTv, a9_parTv,
                b1_parTv, b2_parTv, b3_parTv, b4_parTv, b5_parTv, b6_parTv, b7_parTv, b8_parTv, b9_parTv
        };
        for (int i = 0; i < Pars.length; i++) {
            parTvs[i].setText(String.valueOf(Pars[i] == -1 ? 0 : Pars[i]));
        }
        out_parTv.setText(String.valueOf(getOutPar()));
        in_ParTv.setText(String.valueOf(getInPar()));
        all_ParTv.setText(String.valueOf(outPar + inPar));
    }

    private void setPars(String hole, String par) {
        switch (hole) {
            case "ONE":
                try {
                    if (a1Par == -1) {
                        a1Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "TWO":
                try {
                    if (a2Par == -1) {
                        a2Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "THREE":
                try {
                    if (a3Par == -1) {
                        a3Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "FOUR":
                try {
                    if (a4Par == -1) {
                        a4Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "FIVE":
                try {
                    if (a5Par == -1) {
                        a5Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "SIX":
                try {
                    if (a6Par == -1) {
                        a6Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "SEVEN":
                try {
                    if (a7Par == -1) {
                        a7Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "EIGHT":
                try {
                    if (a8Par == -1) {
                        a8Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "NINE":
                try {
                    if (a9Par == -1) {
                        a9Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "OUT":

                break;
            case "TEN":
                try {
                    if (b1Par == -1) {
                        b1Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "ELEVEN":
                try {
                    if (b2Par == -1) {
                        b2Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "TWELVE":
                try {
                    if (b3Par == -1) {
                        b3Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "THIRTEEN":
                try {
                    if (b4Par == -1) {
                        b4Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "FOURTEEN":
                try {
                    if (b5Par == -1) {
                        b5Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "FIFTEEN":
                try {
                    if (b6Par == -1) {
                        b6Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "SIXTEEN":
                try {
                    if (b7Par == -1) {
                        b7Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "SEVENTEEN":
                try {
                    if (b8Par == -1) {
                        b8Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "EIGHTEEN":
                try {
                    if (b9Par == -1) {
                        b9Par = (int) Float.parseFloat(par);
                    }
                } catch (Exception e) {

                }

                break;
            case "IN":

                break;
            case "TOTAL":

                break;
        }
    }


    //    private boolean OutInAll(String hole) {
//        if (Util.isNull(hole)) {
//            return true;
//        }
//        if ("OUT".equals(hole)
//                || "IN".equals(hole)
//                || "TOTAL".equals(hole)) {
//            return true;
//        }
//        return false;
//    }


    private void setDatas() {
        setParData();
        if (Util.isNull(groupName)) {
            groupName = "";
        }
        if (Util.isNull(mem1Name)) {
            mem1Name = "";
        }
        if (Util.isNull(mem2Name)) {
            mem2Name = "";
        }
        if (Util.isNull(mem3Name)) {
            mem3Name = "";
        }
        if (Util.isNull(mem4Name)) {
            mem4Name = "";
        }
        mem1NameTv.setText(mem1Name);
        mem2NameTv.setText(mem2Name);
        mem3NameTv.setText(mem3Name);
        mem4NameTv.setText(mem4Name);
        int[] memFens = {
                a1Mem1, a1Mem2, a1Mem3, a1Mem4, a2Mem1, a2Mem2, a2Mem3, a2Mem4,
                a3Mem1, a3Mem2, a3Mem3, a3Mem4, a4Mem1, a4Mem2, a4Mem3, a4Mem4,
                a5Mem1, a5Mem2, a5Mem3, a5Mem4, a6Mem1, a6Mem2, a6Mem3, a6Mem4,
                a7Mem1, a7Mem2, a7Mem3, a7Mem4, a8Mem1, a8Mem2, a8Mem3, a8Mem4,
                a9Mem1, a9Mem2, a9Mem3, a9Mem4, outMem1, outMem2, outMem3, outMem4,
                b1Mem1, b1Mem2, b1Mem3, b1Mem4, b2Mem1, b2Mem2, b2Mem3, b2Mem4,
                b3Mem1, b3Mem2, b3Mem3, b3Mem4, b4Mem1, b4Mem2, b4Mem3, b4Mem4,
                b5Mem1, b5Mem2, b5Mem3, b5Mem4, b6Mem1, b6Mem2, b6Mem3, b6Mem4,
                b7Mem1, b7Mem2, b7Mem3, b7Mem4, b8Mem1, b8Mem2, b8Mem3, b8Mem4,
                b9Mem1, b9Mem2, b9Mem3, b9Mem4, inMem1, inMem2, inMem3, inMem4,
                allMem1, allMem2, allMem3, allMem4
        };
        TextView[] Tvs = {
                a1_mem1Tv, a1_mem2Tv, a1_mem3Tv, a1_mem4Tv, a2_mem1Tv, a2_mem2Tv, a2_mem3Tv, a2_mem4Tv,
                a3_mem1Tv, a3_mem2Tv, a3_mem3Tv, a3_mem4Tv, a4_mem1Tv, a4_mem2Tv, a4_mem3Tv, a4_mem4Tv,
                a5_mem1Tv, a5_mem2Tv, a5_mem3Tv, a5_mem4Tv, a6_mem1Tv, a6_mem2Tv, a6_mem3Tv, a6_mem4Tv,
                a7_mem1Tv, a7_mem2Tv, a7_mem3Tv, a7_mem4Tv, a8_mem1Tv, a8_mem2Tv, a8_mem3Tv, a8_mem4Tv,
                a9_mem1Tv, a9_mem2Tv, a9_mem3Tv, a9_mem4Tv, out_mem1Tv, out_mem2Tv, out_mem3Tv, out_mem4Tv,
                b1_mem1Tv, b1_mem2Tv, b1_mem3Tv, b1_mem4Tv, b2_mem1Tv, b2_mem2Tv, b2_mem3Tv, b2_mem4Tv,
                b3_mem1Tv, b3_mem2Tv, b3_mem3Tv, b3_mem4Tv, b4_mem1Tv, b4_mem2Tv, b4_mem3Tv, b4_mem4Tv,
                b5_mem1Tv, b5_mem2Tv, b5_mem3Tv, b5_mem4Tv, b6_mem1Tv, b6_mem2Tv, b6_mem3Tv, b6_mem4Tv,
                b7_mem1Tv, b7_mem2Tv, b7_mem3Tv, b7_mem4Tv, b8_mem1Tv, b8_mem2Tv, b8_mem3Tv, b8_mem4Tv,
                b9_mem1Tv, b9_mem2Tv, b9_mem3Tv, b9_mem4Tv, in_mem1Tv, in_mem2Tv, in_mem3Tv, in_mem4Tv,
                all_mem1Tv, all_mem2Tv, all_mem3Tv, all_mem4Tv
        };
        for (int i = 0; i < memFens.length; i++) {
            if (memFens[i] != -1) {
                Tvs[i].setText(String.valueOf(memFens[i]));
            }
        }
        int[] outInAll = {outMem1, outMem2, outMem3, outMem4, inMem1, inMem2, inMem3, inMem4,
                allMem1, allMem2, allMem3, allMem4};
        TextView[] outInAllTvs = {
                out_mem1Tv, out_mem2Tv, out_mem3Tv, out_mem4Tv, in_mem1Tv, in_mem2Tv, in_mem3Tv, in_mem4Tv,
                all_mem1Tv, all_mem2Tv, all_mem3Tv, all_mem4Tv
        };
        for (int i = 0; i < outInAll.length; i++) {
            if (outInAll[i] != -1) {
                outInAllTvs[i].setText(String.valueOf(outInAll[i]));
            }
        }
    }

    private void setMemResult(String hole, String result, int j) {
        switch (hole) {
            case "ONE":
                if (j == 0) {
                    try {
                        a1Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        a1Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        a1Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        a1Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "TWO":

                if (j == 0) {
                    try {
                        a2Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        a2Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        a2Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        a2Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "THREE":

                if (j == 0) {
                    try {
                        a3Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        a3Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        a3Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        a3Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "FOUR":

                if (j == 0) {
                    try {
                        a4Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        a4Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        a4Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        a4Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "FIVE":

                if (j == 0) {
                    try {
                        a5Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        a5Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        a5Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        a5Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "SIX":

                if (j == 0) {
                    try {
                        a6Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        a6Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        a6Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        a6Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "SEVEN":

                if (j == 0) {
                    try {
                        a7Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        a7Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        a7Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        a7Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "EIGHT":

                if (j == 0) {
                    try {
                        a8Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        a8Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        a8Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        a8Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "NINE":

                if (j == 0) {
                    try {
                        a9Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        a9Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        a9Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        a9Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "OUT":
                if (j == 0) {
                    try {
                        outMem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        outMem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        outMem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        outMem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }

                break;
            case "TEN":

                if (j == 0) {
                    try {
                        b1Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        b1Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        b1Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        b1Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "ELEVEN":

                if (j == 0) {
                    try {
                        b2Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        b2Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        b2Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        b2Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "TWELVE":

                if (j == 0) {
                    try {
                        b3Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        b3Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        b3Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        b3Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "THIRTEEN":

                if (j == 0) {
                    try {
                        b4Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        b4Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        b4Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        b4Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "FOURTEEN":

                if (j == 0) {
                    try {
                        b5Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        b5Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        b5Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        b5Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "FIFTEEN":


                if (j == 0) {
                    try {
                        b6Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        b6Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        b6Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        b6Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "SIXTEEN":

                if (j == 0) {
                    try {
                        b7Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        b7Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        b7Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        b7Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "SEVENTEEN":

                if (j == 0) {
                    try {
                        b8Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        b8Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        b8Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        b8Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "EIGHTEEN":

                if (j == 0) {
                    try {
                        b9Mem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        b9Mem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        b9Mem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        b9Mem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "IN":
                if (j == 0) {
                    try {
                        inMem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        inMem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        inMem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        inMem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
            case "TOTAL":
                if (j == 0) {
                    try {
                        allMem1 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 1) {
                    try {
                        allMem2 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 2) {
                    try {
                        allMem3 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                } else if (j == 3) {
                    try {
                        allMem4 = (int) Float.parseFloat(result);
                    } catch (Exception e) {

                    }
                }
                break;
        }
    }


    private void setDataMap(String hole, List<ResultBean.MemInfo> listMemInfo, boolean isOk) {
        switch (hole) {
            case "ONE":
                dataMap.put(1, listMemInfo);
                stateMap.put(1, isOk);
                break;
            case "TWO":
                dataMap.put(2, listMemInfo);
                stateMap.put(2, isOk);
                break;
            case "THREE":
                dataMap.put(3, listMemInfo);
                stateMap.put(3, isOk);
                break;
            case "FOUR":
                dataMap.put(4, listMemInfo);
                stateMap.put(4, isOk);
                break;
            case "FIVE":
                dataMap.put(5, listMemInfo);
                stateMap.put(5, isOk);
                break;
            case "SIX":
                dataMap.put(6, listMemInfo);
                stateMap.put(6, isOk);
                break;
            case "SEVEN":
                dataMap.put(7, listMemInfo);
                stateMap.put(7, isOk);
                break;
            case "EIGHT":
                dataMap.put(8, listMemInfo);
                stateMap.put(8, isOk);
                break;
            case "NINE":
                dataMap.put(9, listMemInfo);
                stateMap.put(9, isOk);
                break;
//            case "OUT":
//                dataMap.put(100, listMemInfo);
//
//                break;
            case "TEN":
                dataMap.put(10, listMemInfo);
                stateMap.put(10, isOk);
                break;
            case "ELEVEN":
                dataMap.put(11, listMemInfo);
                stateMap.put(11, isOk);
                break;
            case "TWELVE":
                dataMap.put(12, listMemInfo);
                stateMap.put(12, isOk);
                break;
            case "THIRTEEN":
                dataMap.put(13, listMemInfo);
                stateMap.put(13, isOk);
                break;
            case "FOURTEEN":
                dataMap.put(14, listMemInfo);
                stateMap.put(14, isOk);
                break;
            case "FIFTEEN":
                dataMap.put(15, listMemInfo);
                stateMap.put(15, isOk);
                break;
            case "SIXTEEN":
                dataMap.put(16, listMemInfo);
                stateMap.put(16, isOk);
                break;
            case "SEVENTEEN":
                dataMap.put(17, listMemInfo);
                stateMap.put(17, isOk);
                break;
            case "EIGHTEEN":
                dataMap.put(18, listMemInfo);
                stateMap.put(18, isOk);
                break;
//            case "IN":
//                dataMap.put(200, listMemInfo);
//                break;
//            case "TOTAL":
//                dataMap.put(300, listMemInfo);
//                break;
        }
    }

    private Map<Integer, Boolean> stateMap = new HashMap<>(18);
    private int indexCurrent = 0;
    private int IndexBefore = -1;
    private String groupId;
    private String phone;
    private String[] holeNames = {"A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9",
            "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9"};
    private String[] HoleIndexs = {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE",
            "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN"};
    private String[] HoleAll = {"ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE",
            "OUT",
            "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN",
            "IN", "TOTAL"
    };
    private boolean hasIndex;

    private void checkModifyAble(final int type) {
        for (int i = 1; i <= stateMap.size(); i++) {
            if (null == stateMap.get(i) || false == stateMap.get(i)) {
                indexCurrent = i;
                hasIndex = true;
                break;
            }
        }
        if (!hasIndex) {
            indexCurrent = stateMap.size() + 1;
        }
        hasIndex = false;
        if (type == CURRENT) {
            if (indexCurrent > stateMap.size()) {
                Util.show("成绩已填完，请尝试修改上一洞");
                return;
            }
            showWriteDialog(type);
            return;
        }
        if (type == BEFORE) {
            if ((indexCurrent == 1) || (indexCurrent - 1 == 0)) {
                Util.show("没有上一洞可以修改");
                return;
            }
        }
        IndexBefore = indexCurrent - 1;
        showWriteDialog(type);
    }

    private boolean mem1Ok;
    private boolean mem2Ok;
    private boolean mem3Ok;
    private boolean mem4Ok;
    String mem1WriteOn;
    String mem2WriteOn;
    String mem3WriteOn;
    String mem4WriteOn;
    String mem1WritePush;
    String mem2WritePush;
    String mem3WritePush;
    String mem4WritePush;
    String mem1WriteTotal;
    String mem2WriteTotal;
    String mem3WriteTotal;
    String mem4WriteTotal;
    String memPhone;

    private void showWriteDialog(final int type) {
        final Dialog dialog = new Dialog(context, R.style.mDialog);
        View view = getLayoutInflater().inflate(R.layout.dialog_match_group_modify, null);
        View layout = view.findViewById(R.id.dialog_match_group_modify_layout_ll);
        TextView titleTv = (TextView) view.findViewById(R.id.dialog_match_group_modify_title_tv);
        final TextView mem1NameTv = (TextView) view.findViewById(R.id.dialog_match_group_modify_mem1_tv);
        TextView mem2NameTv = (TextView) view.findViewById(R.id.dialog_match_group_modify_mem2_tv);
        TextView mem3NameTv = (TextView) view.findViewById(R.id.dialog_match_group_modify_mem3_tv);
        TextView mem4NameTv = (TextView) view.findViewById(R.id.dialog_match_group_modify_mem4_tv);
        final TextView zongGanMem1Tv = (TextView) view.findViewById(R.id.dialog_match_group_modify_zonggan_mem1_tv);
        final TextView zongGanMem2Tv = (TextView) view.findViewById(R.id.dialog_match_group_modify_zonggan_mem2_tv);
        final TextView zongGanMem3Tv = (TextView) view.findViewById(R.id.dialog_match_group_modify_zonggan_mem3_tv);
        final TextView zongGanMem4Tv = (TextView) view.findViewById(R.id.dialog_match_group_modify_zonggan_mem4_tv);
        final EditText onMem1Et = (EditText) view.findViewById(R.id.dialog_match_group_modify_on_mem1_et);
        final EditText onMem2Et = (EditText) view.findViewById(R.id.dialog_match_group_modify_on_mem2_et);
        final EditText onMem3Et = (EditText) view.findViewById(R.id.dialog_match_group_modify_on_mem3_et);
        final EditText onMem4Et = (EditText) view.findViewById(R.id.dialog_match_group_modify_on_mem4_et);
        final EditText pushMem1Et = (EditText) view.findViewById(R.id.dialog_match_group_modify_push_mem1_et);
        final EditText pushMem2Et = (EditText) view.findViewById(R.id.dialog_match_group_modify_push_mem2_et);
        final EditText pushMem3Et = (EditText) view.findViewById(R.id.dialog_match_group_modify_push_mem3_et);
        final EditText pushMem4Et = (EditText) view.findViewById(R.id.dialog_match_group_modify_push_mem4_et);
        TextView timesTv = (TextView) view.findViewById(R.id.dialog_match_group_modify_times_tv);
        View timesView = view.findViewById(R.id.dialog_match_group_modify_times_ll);
        TextView msgTv = (TextView) view.findViewById(R.id.dialog_match_group_modify_msg_tv);
        final TextView cancelTv = (TextView) view.findViewById(R.id.dialog_match_group_modify_cancel_tv);
        TextView sureTv = (TextView) view.findViewById(R.id.dialog_match_group_modify_sure_tv);

        LinearLayout.LayoutParams ll = (LinearLayout.LayoutParams) layout.getLayoutParams();
        ll.width = getWindowManager().getDefaultDisplay().getWidth() * 4 / 5;
        ll.height = ll.WRAP_CONTENT;
        layout.setLayoutParams(ll);
        AutoUtil.auto(view);
        dialog.setContentView(view);

        String title = "";
        List<ResultBean.MemInfo> listCurrent = new ArrayList<>();
        List<ResultBean.MemInfo> listBefore = new ArrayList<>();
        timesView.setVisibility(View.GONE);

        if (type == BEFORE) {
            msgTv.setVisibility(View.GONE);
            try {
                listBefore = dataMap.get(IndexBefore);
            } catch (Exception e) {

            }
            getMemRes(listBefore);
        } else if (type == CURRENT) {
            msgTv.setVisibility(View.VISIBLE);
            try {
                listCurrent = dataMap.get(indexCurrent);
            } catch (Exception e) {

            }
            getMemRes(listCurrent);
        }
        if (!Util.isNull(mem1WriteOn)) {
            try {
                onMem1Et.setText((int) Float.parseFloat(mem1WriteOn) + "");
            } catch (Exception e) {
                onMem1Et.setText(mem1WriteOn);
            }
        }
        if (!Util.isNull(mem2WriteOn)) {
            try {
                onMem2Et.setText((int) Float.parseFloat(mem2WriteOn) + "");
            } catch (Exception e) {
                onMem2Et.setText(mem2WriteOn);
            }
        }
        if (!Util.isNull(mem3WriteOn)) {
            try {
                onMem3Et.setText((int) Float.parseFloat(mem3WriteOn) + "");
            } catch (Exception e) {
                onMem3Et.setText(mem3WriteOn);
            }
        }
        if (!Util.isNull(mem4WriteOn)) {
            try {
                onMem4Et.setText((int) Float.parseFloat(mem4WriteOn) + "");
            } catch (Exception e) {
                onMem4Et.setText(mem4WriteOn);
            }
        }
        if (!Util.isNull(mem1WritePush)) {
            try {
                pushMem1Et.setText((int) Float.parseFloat(mem1WritePush) + "");
            } catch (Exception e) {
                pushMem1Et.setText(mem1WritePush);
            }
        }
        if (!Util.isNull(mem2WritePush)) {
            try {
                pushMem2Et.setText((int) Float.parseFloat(mem2WritePush) + "");
            } catch (Exception e) {
                pushMem2Et.setText(mem2WritePush);
            }
        }
        if (!Util.isNull(mem3WritePush)) {
            try {
                pushMem3Et.setText((int) Float.parseFloat(mem3WritePush) + "");
            } catch (Exception e) {
                pushMem3Et.setText(mem3WritePush);
            }
        }
        if (!Util.isNull(mem4WritePush)) {
            try {
                pushMem4Et.setText((int) Float.parseFloat(mem4WritePush) + "");
            } catch (Exception e) {
                pushMem4Et.setText(mem4WritePush);
            }
        }
        if (!Util.isNull(mem1WriteTotal)) {
            try {
                zongGanMem1Tv.setText((int) Float.parseFloat(mem1WriteTotal) + "");
            } catch (Exception e) {
                zongGanMem1Tv.setText(mem1WriteTotal);
            }
        } else {
            if (!Util.isNull(mem1WriteOn) && !Util.isNull(mem1WritePush)) {
                try {
                    zongGanMem1Tv.setText((int) (Float.parseFloat(mem1WriteOn) + Float.parseFloat(mem1WritePush)) + "");
                } catch (Exception e) {
                    zongGanMem1Tv.setText("");
                }
            }
        }
        if (!Util.isNull(mem2WriteTotal)) {
            try {
                zongGanMem2Tv.setText((int) Float.parseFloat(mem2WriteTotal) + "");
            } catch (Exception e) {
                zongGanMem2Tv.setText(mem2WriteTotal);
            }
        } else {
            if (!Util.isNull(mem2WriteOn) && !Util.isNull(mem2WritePush)) {
                try {
                    zongGanMem2Tv.setText((int) (Float.parseFloat(mem2WriteOn) + Float.parseFloat(mem2WritePush)) + "");
                } catch (Exception e) {
                    zongGanMem2Tv.setText("");
                }
            }
        }
        if (!Util.isNull(mem3WriteTotal)) {
            try {
                zongGanMem3Tv.setText((int) Float.parseFloat(mem3WriteTotal) + "");
            } catch (Exception e) {
                zongGanMem3Tv.setText(mem3WriteTotal);
            }
        } else {
            if (!Util.isNull(mem3WriteOn) && !Util.isNull(mem3WritePush)) {
                try {
                    zongGanMem3Tv.setText((int) (Float.parseFloat(mem3WriteOn) + Float.parseFloat(mem3WritePush)) + "");
                } catch (Exception e) {
                    zongGanMem3Tv.setText("");
                }
            }
        }
        if (!Util.isNull(mem4WriteTotal)) {
            try {
                zongGanMem4Tv.setText((int) Float.parseFloat(mem4WriteTotal) + "");
            } catch (Exception e) {
                zongGanMem4Tv.setText(mem4WriteTotal);
            }
        } else {
            if (!Util.isNull(mem4WriteOn) && !Util.isNull(mem4WritePush)) {
                try {
                    zongGanMem4Tv.setText((int) (Float.parseFloat(mem4WriteOn) + Float.parseFloat(mem4WritePush)) + "");
                } catch (Exception e) {
                    zongGanMem4Tv.setText("");
                }
            }
        }
        int[] pars = {a1Par, a2Par, a3Par, a4Par, a5Par, a6Par, a7Par, a8Par, a9Par,
                b1Par, b2Par, b3Par, b4Par, b5Par, b6Par, b7Par, b8Par, b9Par};
        try {
            if (type == CURRENT) {
                title = holeNames[indexCurrent - 1] + "洞成绩填写(Par" + pars[indexCurrent - 1] + ")";
            } else if (type == BEFORE) {
                title = holeNames[IndexBefore - 1] + "洞成绩修改(Par" + pars[IndexBefore - 1] + ")";
            }
        } catch (Exception e) {

        }
        titleTv.setText(title);

        if (!Util.isNull(mem1Name)) {
            mem1NameTv.setText(mem1Name);
            mem1Ok = true;
        }
        if (!Util.isNull(mem2Name)) {
            mem2NameTv.setText(mem2Name);
            mem2Ok = true;
        }
        if (!Util.isNull(mem3Name)) {
            mem3NameTv.setText(mem3Name);
            mem3Ok = true;
        }
        if (!Util.isNull(mem4Name)) {
            mem4NameTv.setText(mem4Name);
            mem4Ok = true;
        }
        if (!mem1Ok) {
            onMem1Et.setEnabled(false);
            pushMem1Et.setEnabled(false);
        }
        if (!mem2Ok) {
            onMem2Et.setEnabled(false);
            pushMem2Et.setEnabled(false);
        }
        if (!mem3Ok) {
            onMem3Et.setEnabled(false);
            pushMem3Et.setEnabled(false);
        }
        if (!mem4Ok) {
            onMem4Et.setEnabled(false);
            pushMem4Et.setEnabled(false);
        }

        onMem1Et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String on = onMem1Et.getText().toString().trim();
                String push = pushMem1Et.getText().toString().trim();
                if (Util.isNull(on)) {
                    on = "0";
                }
                if (Util.isNull(push)) {
                    push = "0";
                }
                if (!Util.isNull(on) && !Util.isNull(push)) {
                    try {
                        zongGanMem1Tv.setText(Integer.parseInt(on) + Integer.parseInt(push) + "");
                    } catch (Exception e) {

                    }
                }
            }
        });
        pushMem1Et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String on = onMem1Et.getText().toString().trim();
                String push = pushMem1Et.getText().toString().trim();
                if (Util.isNull(on)) {
                    on = "0";
                }
                if (Util.isNull(push)) {
                    push = "0";
                }
                if (!Util.isNull(on) && !Util.isNull(push)) {
                    try {
                        zongGanMem1Tv.setText(Integer.parseInt(on) + Integer.parseInt(push) + "");
                    } catch (Exception e) {

                    }
                }
            }
        });
        onMem2Et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String on = onMem2Et.getText().toString().trim();
                String push = pushMem2Et.getText().toString().trim();
                if (Util.isNull(on)) {
                    on = "0";
                }
                if (Util.isNull(push)) {
                    push = "0";
                }
                if (!Util.isNull(on) && !Util.isNull(push)) {
                    try {
                        zongGanMem2Tv.setText(Integer.parseInt(on) + Integer.parseInt(push) + "");
                    } catch (Exception e) {

                    }
                }
            }
        });
        pushMem2Et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String on = onMem2Et.getText().toString().trim();
                String push = pushMem2Et.getText().toString().trim();
                if (Util.isNull(on)) {
                    on = "0";
                }
                if (Util.isNull(push)) {
                    push = "0";
                }
                if (!Util.isNull(on) && !Util.isNull(push)) {
                    try {
                        zongGanMem2Tv.setText(Integer.parseInt(on) + Integer.parseInt(push) + "");
                    } catch (Exception e) {

                    }
                }
            }
        });
        onMem3Et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String on = onMem3Et.getText().toString().trim();
                String push = pushMem3Et.getText().toString().trim();
                if (Util.isNull(on)) {
                    on = "0";
                }
                if (Util.isNull(push)) {
                    push = "0";
                }
                if (!Util.isNull(on) && !Util.isNull(push)) {
                    try {
                        zongGanMem3Tv.setText(Integer.parseInt(on) + Integer.parseInt(push) + "");
                    } catch (Exception e) {

                    }
                }
            }
        });
        pushMem3Et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String on = onMem3Et.getText().toString().trim();
                String push = pushMem3Et.getText().toString().trim();
                if (Util.isNull(on)) {
                    on = "0";
                }
                if (Util.isNull(push)) {
                    push = "0";
                }
                if (!Util.isNull(on) && !Util.isNull(push)) {
                    try {
                        zongGanMem3Tv.setText(Integer.parseInt(on) + Integer.parseInt(push) + "");
                    } catch (Exception e) {

                    }
                }
            }
        });
        onMem4Et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String on = onMem4Et.getText().toString().trim();
                String push = pushMem4Et.getText().toString().trim();
                if (Util.isNull(on)) {
                    on = "0";
                }
                if (Util.isNull(push)) {
                    push = "0";
                }
                if (!Util.isNull(on) && !Util.isNull(push)) {
                    try {
                        zongGanMem4Tv.setText(Integer.parseInt(on) + Integer.parseInt(push) + "");
                    } catch (Exception e) {

                    }
                }
            }
        });
        pushMem4Et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String on = onMem4Et.getText().toString().trim();
                String push = pushMem4Et.getText().toString().trim();
                if (Util.isNull(on)) {
                    on = "0";
                }
                if (Util.isNull(push)) {
                    push = "0";
                }
                if (!Util.isNull(on) || !Util.isNull(push)) {
                    try {
                        zongGanMem4Tv.setText(Integer.parseInt(on) + Integer.parseInt(push) + "");
                    } catch (Exception e) {

                    }
                }
            }
        });


        cancelTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        sureTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String mem1On = onMem1Et.getText().toString().trim();
                String mem2On = onMem2Et.getText().toString().trim();
                String mem3On = onMem3Et.getText().toString().trim();
                String mem4On = onMem4Et.getText().toString().trim();
                String mem1Push = pushMem1Et.getText().toString().trim();
                String mem2Push = pushMem2Et.getText().toString().trim();
                String mem3Push = pushMem3Et.getText().toString().trim();
                String mem4Push = pushMem4Et.getText().toString().trim();
                String mem1Total = zongGanMem1Tv.getText().toString().trim();
                String mem2Total = zongGanMem2Tv.getText().toString().trim();
                String mem3Total = zongGanMem3Tv.getText().toString().trim();
                String mem4Total = zongGanMem4Tv.getText().toString().trim();
                List<Mems> list = new ArrayList<Mems>();
                boolean mem1Has = false;
                boolean mem2Has = false;
                boolean mem3Has = false;
                boolean mem4Has = false;

                String[] mem = {
                        mem1On, mem2On, mem3On, mem4On, mem1Push, mem2Push, mem3Push, mem4Push
                };
                boolean allNull = true;
                for (int i = 0; i < mem.length; i++) {
                    if (!Util.isNull(mem[i])) {
                        allNull = false;
                        break;
                    }
                }
                if (allNull) {
                    dialog.dismiss();
                    return;
                }
                if (!Util.isNull(mem1On) || !Util.isNull(mem1Push)) {
                    mem1Has = true;
                }
                if (!Util.isNull(mem2On) || !Util.isNull(mem2Push)) {
                    mem2Has = true;
                }
                if (!Util.isNull(mem3On) || !Util.isNull(mem3Push)) {
                    mem3Has = true;
                }
                if (!Util.isNull(mem4On) || !Util.isNull(mem4Push)) {
                    mem4Has = true;
                }
                if (mem1Ok) {
                    if (type == BEFORE) {
                        if (Util.isNull(mem1On) || Util.isNull(mem1Push)) {
                            Util.show("修改成绩不能为空");
                            return;
                        }
                    }
                    if (mem1Has) {
                        Mems m = new Mems();
                        m.competitorName = mem1Name;
                        if (type == CURRENT) {
                            try {
                                String hole = HoleIndexs[indexCurrent - 1];
                                m.competitionHole = hole;
                            } catch (Exception e) {

                            }
                            try {
                                m.position = dataMap.get(indexCurrent).get(0).position;
                            } catch (Exception e) {

                            }

                            try {
                                m.phone = dataMap.get(indexCurrent).get(0).phone;
                            } catch (Exception e) {

                            }
                        } else if (type == BEFORE) {
                            try {
                                String hole = HoleIndexs[IndexBefore - 1];
                                m.competitionHole = hole;
                            } catch (Exception e) {

                            }
                            try {
                                m.position = dataMap.get(IndexBefore).get(0).position;
                            } catch (Exception e) {

                            }

                            try {
                                m.phone = dataMap.get(IndexBefore).get(0).phone;
                            } catch (Exception e) {

                            }
                        }
                        if (Util.isNull(mem1On)) {
                            mem1On = "";
                        }
                        if (Util.isNull(mem1Push)) {
                            mem1Push = "";
                        }
                        if (Util.isNull(mem1Total)) {
                            if (!Util.isNull(mem1On) && !Util.isNull(mem1Push)) {
                                try {
                                    mem1Total = (Integer.parseInt(mem1On) + Integer.parseInt(mem1Push)) + "";
                                } catch (Exception e) {
                                    mem1Total = "";
                                }

                            }
                        }
                        m.onScore = mem1On;
                        m.pushScore = mem1Push;
                        m.totalScore = mem1Total;
                        list.add(m);
                    }

                }
                if (mem2Ok) {
                    if (type == BEFORE) {
                        if (Util.isNull(mem2On) || Util.isNull(mem2Push)) {
                            Util.show("修改成绩不能为空");
                            return;
                        }
                    }
                    if (mem2Has) {
                        Mems m = new Mems();
                        m.competitorName = mem2Name;
                        if (type == CURRENT) {
                            try {
                                String hole = HoleIndexs[indexCurrent - 1];
                                m.competitionHole = hole;
                            } catch (Exception e) {

                            }
                            try {
                                m.position = dataMap.get(indexCurrent).get(1).position;
                            } catch (Exception e) {

                            }

                            try {
                                m.phone = dataMap.get(indexCurrent).get(1).phone;
                            } catch (Exception e) {

                            }
                        } else if (type == BEFORE) {
                            try {
                                String hole = HoleIndexs[IndexBefore - 1];
                                m.competitionHole = hole;
                            } catch (Exception e) {

                            }
                            try {
                                m.position = dataMap.get(IndexBefore).get(1).position;
                            } catch (Exception e) {

                            }

                            try {
                                m.phone = dataMap.get(IndexBefore).get(1).phone;
                            } catch (Exception e) {

                            }
                        }
                        if (Util.isNull(mem2On)) {
                            mem2On = "";
                        }
                        if (Util.isNull(mem2Push)) {
                            mem2Push = "";
                        }
                        if (Util.isNull(mem2Total)) {
                            if (!Util.isNull(mem2On) && !Util.isNull(mem2Push)) {
                                try {
                                    mem2Total = (Integer.parseInt(mem2On) + Integer.parseInt(mem2Push)) + "";
                                } catch (Exception e) {
                                    mem2Total = "";
                                }

                            }
                        }
                        m.onScore = mem2On;
                        m.pushScore = mem2Push;
                        m.totalScore = mem2Total;
                        list.add(m);
                    }
                }
                if (mem3Ok) {
                    if (type == BEFORE) {
                        if (Util.isNull(mem3On) || Util.isNull(mem3Push)) {
                            Util.show("修改成绩不能为空");
                            return;
                        }
                    }
                    if (mem3Has) {

                        Mems m = new Mems();
                        m.competitorName = mem3Name;
                        if (type == CURRENT) {
                            try {
                                String hole = HoleIndexs[indexCurrent - 1];
                                m.competitionHole = hole;
                            } catch (Exception e) {

                            }
                            try {
                                m.position = dataMap.get(indexCurrent).get(2).position;
                            } catch (Exception e) {

                            }

                            try {
                                m.phone = dataMap.get(indexCurrent).get(2).phone;
                            } catch (Exception e) {

                            }
                        } else if (type == BEFORE) {
                            try {
                                String hole = HoleIndexs[IndexBefore - 1];
                                m.competitionHole = hole;
                            } catch (Exception e) {

                            }
                            try {
                                m.position = dataMap.get(IndexBefore).get(2).position;
                            } catch (Exception e) {

                            }

                            try {
                                m.phone = dataMap.get(IndexBefore).get(2).phone;
                            } catch (Exception e) {

                            }
                        }
                        if (Util.isNull(mem3On)) {
                            mem3On = "";
                        }
                        if (Util.isNull(mem3Push)) {
                            mem3Push = "";
                        }
                        if (Util.isNull(mem3Total)) {
                            if (!Util.isNull(mem3On) && !Util.isNull(mem3Push)) {
                                try {
                                    mem3Total = (Integer.parseInt(mem3On) + Integer.parseInt(mem3Push)) + "";
                                } catch (Exception e) {
                                    mem3Total = "";
                                }

                            }
                        }
                        m.onScore = mem3On;
                        m.pushScore = mem3Push;
                        m.totalScore = mem3Total;
                        list.add(m);
                    }
                }
                if (mem4Ok) {
                    if (type == BEFORE) {
                        if (Util.isNull(mem4On) || Util.isNull(mem4Push)) {
                            Util.show("修改成绩不能为空");
                            return;
                        }
                    }
                    if (mem4Has) {
                        Mems m = new Mems();
                        m.competitorName = mem4Name;
                        if (type == CURRENT) {
                            try {
                                String hole = HoleIndexs[indexCurrent - 1];
                                m.competitionHole = hole;
                            } catch (Exception e) {

                            }
                            try {
                                m.position = dataMap.get(indexCurrent).get(3).position;
                            } catch (Exception e) {

                            }

                            try {
                                m.phone = dataMap.get(indexCurrent).get(3).phone;
                            } catch (Exception e) {

                            }
                        } else if (type == BEFORE) {
                            try {
                                String hole = HoleIndexs[IndexBefore - 1];
                                m.competitionHole = hole;
                            } catch (Exception e) {

                            }
                            try {
                                m.position = dataMap.get(IndexBefore).get(3).position;
                            } catch (Exception e) {

                            }

                            try {
                                m.phone = dataMap.get(IndexBefore).get(3).phone;
                            } catch (Exception e) {

                            }
                        }
                        if (Util.isNull(mem4On)) {
                            mem4On = "";
                        }
                        if (Util.isNull(mem4Push)) {
                            mem4Push = "";
                        }
                        if (Util.isNull(mem4Total)) {
                            if (!Util.isNull(mem4On) && !Util.isNull(mem4Push)) {
                                try {
                                    mem4Total = (Integer.parseInt(mem4On) + Integer.parseInt(mem4Push)) + "";
                                } catch (Exception e) {
                                    mem4Total = "";
                                }

                            }
                        }
                        m.onScore = mem4On;
                        m.pushScore = mem4Push;
                        m.totalScore = mem4Total;
                        list.add(m);
                    }
                }
                dialog.dismiss();
                setResult(list, type);


            }
        });
        dialog.show();
    }

    private void getMemRes(List<ResultBean.MemInfo> list) {
        if (null != list && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                memPhone = list.get(i).phone;
                if (Util.isNull(memPhone)) {
                    continue;
                }
                if (!Util.isNull(mem1Phone) && memPhone.equals(mem1Phone)) {
                    mem1WriteOn = list.get(i).onScore;
                    mem1WritePush = list.get(i).pushScore;
                    mem1WriteTotal = list.get(i).totalScore;
                } else if (!Util.isNull(mem2Phone) && mem2Phone.equals(memPhone)) {
                    mem2WriteOn = list.get(i).onScore;
                    mem2WritePush = list.get(i).pushScore;
                    mem2WriteTotal = list.get(i).totalScore;
                } else if (!Util.isNull(mem3Phone) && mem3Phone.equals(memPhone)) {
                    mem3WriteOn = list.get(i).onScore;
                    mem3WritePush = list.get(i).pushScore;
                    mem3WriteTotal = list.get(i).totalScore;
                } else if (!Util.isNull(mem4Phone) && mem4Phone.equals(memPhone)) {
                    mem4WriteOn = list.get(i).onScore;
                    mem4WritePush = list.get(i).pushScore;
                    mem4WriteTotal = list.get(i).totalScore;
                }


            }
        }
    }

    private void setResult(List<Mems> list, final int type) {
        String url = WebAPI.group_result_and_or_modify_put;
        Map<String, Object> map = new HashMap<>();
        JSONObject json = new JSONObject();
        JSONArray array = new JSONArray();
        try {
            json.put("competitionGroupId", groupId);
            if (null != list && list.size() > 0) {
                JSONObject scoresJson;
                for (int i = 0; i < list.size(); i++) {
                    scoresJson = new JSONObject();
                    scoresJson.put("competitionHole", list.get(i).competitionHole);
                    scoresJson.put("onScore", list.get(i).onScore);
                    scoresJson.put("pushScore", list.get(i).pushScore);
                    scoresJson.put("phone", list.get(i).phone);
                    array.put(scoresJson);
                }

            }
            json.put("updateScoreDtos", array);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        map.put("token", UserData.getUser() == null ? "" : UserData.getUser().getToken());
        map.put("scoresDto", json);
        AnimaUtil.showLoading(context);
        Web.putjsonOk(url, map, new NetCallBack(new INetCallBack() {
            @Override
            public void onResponse(NetResponse response) {
                AnimaUtil.stopLoading();
                if (200 != response.statusCode) {
                    if (!Util.isNull(response.errorMsg)) {
                        Util.show(response.result);
                        return;
                    }
                    Util.showNetError();
                    return;
                }
                if (type == CURRENT) {
                    Util.show("添加成功");
                } else {
                    Util.show("修改成功");
                }
                refreshData();
            }

        }));
    }

    private void refreshData() {
        getGroupInfo();
    }

    private void getSum() {
        getOutMem1();
        getOutMem2();
        getOutMem3();
        getOutMem4();
        getInMem1();
        getInMem2();
        getInMem3();
        getInMem4();
        getAllMem1();
        getAllMem2();
        getAllMem3();
        getAllMem4();

    }

    private void getAllMem4() {
        int[] out = {
                a1Mem4, a2Mem4, a3Mem4, a4Mem4, a5Mem4, a6Mem4, a7Mem4, a8Mem4, a9Mem4,
                b1Mem4, b2Mem4, b3Mem4, b4Mem4, b5Mem4, b6Mem4, b7Mem4, b8Mem4, b9Mem4
        };

        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        allMem4 = result;
    }

    private void getAllMem3() {
        int[] out = {
                a1Mem3, a2Mem3, a3Mem3, a4Mem3, a5Mem3, a6Mem3, a7Mem3, a8Mem3, a9Mem3,
                b1Mem3, b2Mem3, b3Mem3, b4Mem3, b5Mem3, b6Mem3, b7Mem3, b8Mem3, b9Mem3
        };

        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        allMem3 = result;
    }

    private void getAllMem2() {
        int[] out = {
                a1Mem2, a2Mem2, a3Mem2, a4Mem2, a5Mem2, a6Mem2, a7Mem2, a8Mem2, a9Mem2,
                b1Mem2, b2Mem2, b3Mem2, b4Mem2, b5Mem2, b6Mem2, b7Mem2, b8Mem2, b9Mem2
        };

        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        allMem2 = result;
    }

    private void getAllMem1() {
        int[] out = {
                a1Mem1, a2Mem1, a3Mem1, a4Mem1, a5Mem1, a6Mem1, a7Mem1, a8Mem1, a9Mem1,
                b1Mem1, b2Mem1, b3Mem1, b4Mem1, b5Mem1, b6Mem1, b7Mem1, b8Mem1, b9Mem1
        };

        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        allMem1 = result;
    }

    private void getInMem1() {
        int[] out = {
                b1Mem1, b2Mem1, b3Mem1, b4Mem1, b5Mem1, b6Mem1, b7Mem1, b8Mem1, b9Mem1
        };
        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        inMem1 = result;
    }

    private void getInMem2() {
        int[] out = {
                b1Mem2, b2Mem2, b3Mem2, b4Mem2, b5Mem2, b6Mem2, b7Mem2, b8Mem2, b9Mem2
        };
        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        inMem2 = result;
    }

    private void getInMem3() {
        int[] out = {
                b1Mem3, b2Mem3, b3Mem3, b4Mem3, b5Mem3, b6Mem3, b7Mem3, b8Mem3, b9Mem3
        };
        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        inMem3 = result;
    }

    private void getInMem4() {
        int[] out = {
                b1Mem4, b2Mem4, b3Mem4, b4Mem4, b5Mem4, b6Mem4, b7Mem4, b8Mem4, b9Mem4
        };
        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        inMem4 = result;
    }

    private void getOutMem4() {
        int[] out = {
                a1Mem4, a2Mem4, a3Mem4, a4Mem4, a5Mem4, a6Mem4, a7Mem4, a8Mem4, a9Mem4
        };
        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        outMem4 = result;
    }

    private void getOutMem3() {
        int[] out = {
                a1Mem3, a2Mem3, a3Mem3, a4Mem3, a5Mem3, a6Mem3, a7Mem3, a8Mem3, a9Mem3
        };
        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        outMem3 = result;
    }

    private void getOutMem2() {
        int[] out = {
                a1Mem2, a2Mem2, a3Mem2, a4Mem2, a5Mem2, a6Mem2, a7Mem2, a8Mem2, a9Mem2
        };
        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        outMem2 = result;
    }

    private void getOutMem1() {
        int[] out = {
                a1Mem1, a2Mem1, a3Mem1, a4Mem1, a5Mem1, a6Mem1, a7Mem1, a8Mem1, a9Mem1
        };
        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        outMem1 = result;
    }

    private String getOutPar() {
        int[] out = {
                a1Par, a2Par, a3Par, a4Par, a5Par, a6Par, a7Par, a8Par, a9Par
        };
        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        outPar = result;
        return String.valueOf(result);
    }

    private String getInPar() {
        int[] out = {
                b1Par, b2Par, b3Par, b4Par, b5Par, b6Par, b7Par, b8Par, b9Par
        };
        int result = 0;
        for (int i = 0; i < out.length; i++) {
            if (out[i] == -1) {
                out[i] = 0;
            }
            result += out[i];
        }
        inPar = result;
        return String.valueOf(result);
    }

    class Mems {
        public String competitorFrom;
        public String competitorName;
        public String phone;
        public String position;
        public String positionStatus;
        public String competitionHole;
        public String onScore;
        public String pushScore;
        public String totalScore;


    }


}
